    <template>
        <div class="boxs">
            <el-card>
                <el-form :model="queryParams" ref="queryForm" :inline="true">
                    <el-form-item label="type">
                        <el-select v-model="queryParams.type" @change="handleQuery">
                            <el-option v-for="item in typeList" :key="item.id" :label="item.name"
                                :value="item.name"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="reason">
                        <el-select v-model="queryParams.reason" @change="handleQuery">
                            <el-option v-for="item in reasonList" :key="item.id" :label="item.name"
                                :value="item.name"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="EnvType">
                        <el-select v-model="queryParams.pk" @change="handleQuery">
                            <el-option v-for="item in environmentList" :key="item.id" :label="item.name"
                                :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="时间范围">
                        <el-date-picker v-model="value1" value-format="yyyy-MM-dd" type="daterange" range-separator="-"
                            :start-placeholder="$t('table.start')" :end-placeholder="$t('table.end')"
                            @change="timeChange">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" size="small"
                            @click="handleQuery">{{ $t('table.search') }}</el-button>
                        <el-button icon="el-icon-refresh" size="small"
                            @click="resetQuery">{{ $t('table.reset') }}</el-button>
                    </el-form-item>
                </el-form>
                <!-- <div class="flex_between">
                <div>RequestRecord</div>
            </div> -->
                <el-table border :data="moreArr" style="margin-top: 15px" v-loading="loading">
                    <el-table-column label="url" align="center" prop="url" width="200">
                        <template slot-scope="scope">
                            <div>
                                <img :src="scope.row.url" alt="Image"
                                    style="max-width: 100px; max-height: 100px; cursor: pointer;"
                                    @click="openDialog(scope.row.url)" />
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column label="content" align="center" prop="error">
                        <template slot-scope="scope">
                            <div style="cursor: pointer;color: blue; overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;  
  line-clamp: 2; 
  text-overflow: ellipsis; " @click="openDialogs(scope.row.content)">
                                {{ scope.row.content }}
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column label="reasonDetail" align="center" prop="reasonDetail" />


                    <el-table-column label="update_date" align="center" width="180" prop="update_date">
                    </el-table-column>
                    <!-- <el-table-column :label="$t('feedback.operate')" align="center" width="180">
                    <template slot-scope="scope">
                        <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">Check</el-button>
                        <el-button size="mini" type="danger"
                            @click="handleDelete(scope.$index, scope.row)">delete</el-button>

                    </template>

                </el-table-column> -->
                </el-table>
                <pagination v-show="total > 0" :total="total" :page.sync="queryParams.page"
                    :limit.sync="queryParams.size" @pagination="getMore" />
            </el-card>

            <el-dialog :visible.sync="dialogVisible" @close="dialogVisible = false">
                <img :src="currentImageUrl" alt="Large Image" style="width: 100%;" />
            </el-dialog>
            <el-dialog title="result" :visible.sync="dialogVisible1" width="800px">
                <div>
                    <v-md-preview :text="messageRes"></v-md-preview>
                </div>
            </el-dialog>
        </div>
    </template>
<script>
import { getApplicationList, restoreUserSubscriptionStatus, deleteHandel } from "@/api/SubscriptionRevive";
import { getSurveyResponse } from "@/api/beauty";

import pk from "@/utils/pk";
export default {
    name: "RequestRecord",
    data() {
        return {
            environmentList: [
                {
                    id: 'com.seamobitech.BeautyAI',
                    name: 'Production'
                },
                {
                    id: 'com.tcdemotc.testApp',
                    name: 'Testing'
                },
            ],
            currentImageUrl: '',
            queryParams: {
                page: 1,
                size: 10,
                dateRange: {
                    start: "",
                    end: "",
                },
                reason: '',
                pk: 'com.seamobitech.BeautyAI',
                type: 'sk'
            },
            typeList: [
                {
                    id: 'sk',
                    name: 'sk'
                },
                {
                    id: 'product',
                    name: 'product'
                },
            ],
            reasonList: [
                {
                    id: 'The insights were unclear',
                    name: 'The insights were unclear'
                },
                {
                    id: "Didn’t match my skin condition",
                    name: "Didn’t match my skin condition"
                },
                {
                    id: 'Not sure how to use the results',
                    name: 'Not sure how to use the results'
                },
                {
                    id: 'Too generic/not detailed enough',
                    name: 'Too generic/not detailed enough'
                },
                {
                    id: 'Expect more personalized advice',
                    name: 'Expect more personalized advice'
                },
                {
                    id: 'Other',
                    name: 'Other'
                },
            ],
            stateList: [
                {
                    id: 'face',
                    name: 'face'
                },
                {
                    id: 'makeup',
                    name: 'makeup'
                },
                {
                    id: 'product',
                    name: 'product'
                },
            ],
            productIdList: [
                {
                    name: 'subs.week',
                    id: 'subs.week'
                },
                {
                    name: 'subs.week.premium',
                    id: 'subs.week.premium'
                },
                {
                    name: 'subs.month',
                    id: 'subs.month'
                },
                {
                    name: 'subs.month.premium',
                    id: 'subs.month.premium'
                },
                {
                    name: 'subs.year',
                    id: 'subs.year'
                },
                {
                    name: 'subs.year.premium',
                    id: 'subs.year.premium'
                },
                {
                    name: 'pro.lifetime',
                    id: 'pro.lifetime'
                },
                {
                    name: 'NA',
                    id: 'NA'
                },
            ],
            total: 0,
            loading: false,
            addLoading: false,
            moreArr: [],
            dialogVisible: false,
            dialogVisible1: false,

            messageRes: '',
            form: {
                description: "",
                file: "",
            },
            search: "",
            rules: {
                token: [
                    { required: true, message: "Please enter token", trigger: "blur" },
                ],
                productId: [{ required: true, message: "Please enter productId", trigger: "change" }],
            },
            value1: "",
        };
    },
    watch: {
        'queryParams.type'(newVal) {
            this.queryParams.reason = ''; // Set to NA ID

            if (newVal == 'sk') {
                this.reasonList = [
                    {
                        id: 'The insights were unclear',
                        name: 'The insights were unclear'
                    },
                    {
                        id: "Didn’t match my skin condition",
                        name: "Didn’t match my skin condition"
                    },
                    {
                        id: 'Not sure how to use the results',
                        name: 'Not sure how to use the results'
                    },
                    {
                        id: 'Too generic/not detailed enough',
                        name: 'Too generic/not detailed enough'
                    },
                    {
                        id: 'Expect more personalized advice',
                        name: 'Expect more personalized advice'
                    },
                    {
                        id: 'Other',
                        name: 'Other'
                    },
                ]
            } else {
                this.reasonList = [
                    {
                        id: 'The product details were inaccurate',
                        name: 'The product details were inaccurate'
                    },
                    {
                        id: 'Missing important ingredients',
                        name: 'Missing important ingredients'
                    },
                    {
                        id: 'The skin match insights were unclear',
                        name: 'The skin match insights were unclear'
                    },
                    {
                        id: 'Expected deeper insights',
                        name: 'Expected deeper insights'
                    },
                    {
                        id: `Couldn’t find some products`,
                        name: `Couldn’t find some products`
                    },
                    {
                        id: 'Other',
                        name: 'Other'
                    },
                ]
            }
        }
    },
    created() {
        this.getMore();
        // this.init()
    },
    methods: {
        openDialogs(content) {
            this.messageRes = content
            this.dialogVisible1 = true
        },

        copyOrder() {
            const input = document.createElement('textarea');
            input.value = this.form.orderId;
            document.body.appendChild(input);
            input.select();
            try {
                document.execCommand('copy');
                this.$message({
                    message: 'Text copied to clipboard!',
                    type: 'success'
                });
            } catch (err) {
                this.$message({
                    message: 'Failed to copy text.',
                    type: 'error'
                });
            }
            document.body.removeChild(input);

        },
        copyOrder1(data1) {
            let data = this.extractErrorFromJsonString(data1)
            const input = document.createElement('textarea');
            input.value = data;
            document.body.appendChild(input);
            input.select();
            try {
                document.execCommand('copy');
                this.$message({
                    message: 'Text copied to clipboard!',
                    type: 'success'
                });
            } catch (err) {
                this.$message({
                    message: 'Failed to copy text.',
                    type: 'error'
                });
            }
            document.body.removeChild(input);
        },
        extractErrorFromJsonString(jsonString) {
            if (JSON.parse(jsonString).content && JSON.parse(jsonString).content.includes('```json')) {
                if (JSON.parse(jsonString).content.charAt(0) === '`') {
                    if (JSON.parse(JSON.parse(jsonString).content.replace(/```json|```/g, '').trim()).error) {
                        return JSON.parse(JSON.parse(jsonString).content.replace(/```json|```/g, '').trim()).error
                    } else {
                        return jsonString
                    }
                } else {
                    return JSON.parse(jsonString).content

                }

            } else {

                return JSON.parse(jsonString).refusal || JSON.parse(jsonString).content
            }
        },
        copyEmail() {
            const input = document.createElement('textarea');
            input.value = this.form.email;
            document.body.appendChild(input);
            input.select();
            try {
                document.execCommand('copy');
                this.$message({
                    message: 'Text copied to clipboard!',
                    type: 'success'
                });
            } catch (err) {
                this.$message({
                    message: 'Failed to copy text.',
                    type: 'error'
                });
            }
            document.body.removeChild(input);

        },
        copyEmail1(data) {
            const input = document.createElement('textarea');
            input.value = data;
            document.body.appendChild(input);
            input.select();
            try {
                document.execCommand('copy');
                this.$message({
                    message: 'Text copied to clipboard!',
                    type: 'success'
                });
            } catch (err) {
                this.$message({
                    message: 'Failed to copy text.',
                    type: 'error'
                });
            }
            document.body.removeChild(input);
        },
        uploadHandel(e) {
            this.form.file = e.file;
        },
        remeveFile() {
            this.form.file = "";
        },
        timeChange() {
            this.queryParams.dateRange.start = this.value1[0];
            this.queryParams.dateRange.end = this.value1[1];
            this.handleQuery();
        },
        getKeyByValue(object, value) {
            return Object.keys(object).find((key) => object[key] === value);
        },
        async getMore() {
            this.loading = true;
            let { data, total } = await getSurveyResponse(this.queryParams);
            this.loading = false;
            this.moreArr = data;
            this.total = total;
        },

        handleQuery() {

            this.queryParams.page = 1;
            this.getMore();
        },
        async affirm() {
            this.$refs["ruleForm"].validate(async (valid) => {
                if (!valid) return;
                try {
                    this.addLoading = true;
                    await restoreUserSubscriptionStatus(this.form);
                    this.addLoading = false;
                    this.$message.success("操作成功");
                    this.getMore();
                    this.dialogVisible = false;
                } catch (e) {
                    this.addLoading = false;
                }
            });
        },
        openDialog(url) {
            this.currentImageUrl = url;
            this.dialogVisible = true;
        },
        handleEdit(i, row) {
            if (row.images) {
                row.imagesList = row.images.split('|')
            }
            if (row.state == '0') {
                row.state = '1'
            }
            this.form = Object.assign({}, row);
            if (this.$refs.upload) {
                this.$refs.upload.clearFiles(); // 清除文件列表
            }
            this.dialogVisible = true;
        },
        handleDelete(index, row) {
            this.$confirm(this.$t('review.deleteText1'), this.$t('review.deleteText2'), {
                confirmButtonText: this.$t('review.confirm'),
                cancelButtonText: this.$t('review.close'),
                type: "error",
            }).then(async () => {
                await deleteHandel({ id: row.id });
                this.getMore();
                this.$message({
                    message: "success!",
                    type: "success",
                });
            });
        },
        resetQuery() {
            this.queryParams.pk = 'com.seamobitech.BeautyAI';
            this.queryParams.type = 'sk';
            this.queryParams.reason = null;
            this.queryParams.package_name = null;
            this.queryParams.dateRange.start = null;
            this.queryParams.dateRange.end = null;
            this.queryParams.page = 1;
            this.value1 = "";
            this.getMore();
        },
    },
};
</script>
<style lang="scss" scoped>
.boxs {
    padding: 20px;
}

::v-deep.el-input.is-disabled .el-input__inner {
    color: #333 !important;
}

::v-deep.el-textarea.is-disabled .el-textarea__inner {
    color: #333 !important;
}

::v-deep .el-upload {
    width: 100% !important;
}

::v-deep .el-upload-dragger {
    width: 100% !important;
}
</style>